//
// Created by xili on 2024/10/8 18:02.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    bool leafSimilar(TreeNode *root1, TreeNode *root2) {
        vector<int> v1;
        vector<int> v2;
        dfs(root1, v1);
        dfs(root2, v2);
        return v1 == v2;
    }

    void dfs(TreeNode *root, vector<int> &v) {
        if (!root->left && !root->right) {
            v.push_back(root->val);
            return;
        }
        if (root->left) {
            dfs(root->left, v);
        }
        if (root->right) {
            dfs(root->right, v);
        }
    }
};